View Javadoc
1 /* 2 * Copyright (c) 2001 by 3 * Siegfried GOESCHL <mailto:siegfried.goeschl@itserv.at>; 4 * and Dima STADNIK <mailto:5d5@mail.ru>; 5 * 6 * This program is free software. 7 * 8 * You may redistribute it and/or modify it under the terms of the GNU 9 * General Public License as published by the Free Software Foundation. 10 * Version 2 of the license should be included with this distribution in 11 * the file LICENSE, as well as License.html. If the license is not 12 * included with this distribution, you may find a copy at the FSF web 13 * site at 'www.gnu.org' or 'www.fsf.org', or you may write to the 14 * Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139 USA. 15 * 16 * THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND, 17 * NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR 18 * OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY 19 * CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR 20 * REDISTRIBUTION OF THIS SOFTWARE. 21 */ 22 23 package junit.extensions.util; 24 25 26 import java.util.StringTokenizer; 27 28 29 /*** 30 * Utility class that provides convinient access to application parameters. 31 * 32 * @author Siegfried GOESCHL 33 */ 34 public class Parameters { 35 36 /*** Parameters. */ 37 protected static String[] parameters; 38 39 /*** 40 * Initializes parameters using system property if they were not initialized before. 41 * 42 * @param propertyKey Key of system property. 43 */ 44 public static synchronized String[] getParameters(String propertyKey) { 45 if (parameters == null) { 46 String property = System.getProperty(propertyKey); 47 48 if (property == null) { 49 parameters = new String[0]; 50 } else { 51 StringTokenizer tokenizer = new StringTokenizer(property, " \t%"); 52 53 parameters = new String[tokenizer.countTokens()]; 54 int i = 0; 55 56 while (tokenizer.hasMoreTokens()) { 57 parameters[i++] = tokenizer.nextToken(); 58 } 59 } 60 } 61 return parameters; 62 } 63 64 /*** 65 * Explicitly initializes parameters if they were not initialized before. 66 * 67 * @param parameters New value. 68 */ 69 public static synchronized void setParameters(String[] parameters) { 70 if (Parameters.parameters == null) { 71 Parameters.parameters = parameters; 72 } 73 } 74 75 /*** 76 * Combines parameters in single string. 77 * 78 * @return Parameters separated by spaces. 79 */ 80 public static synchronized String toLine() { 81 if (parameters == null) { 82 return ""; 83 } 84 StringBuffer buffer = new StringBuffer(128); 85 86 for (int i = 0; i < parameters.length; i++) { 87 buffer.append(parameters[i]); 88 buffer.append(' '); 89 } 90 return buffer.toString(); 91 } 92 } 93

This page was automatically generated by Maven